package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IDeptMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper emMapper;
    @Autowired
    private IDeptMapper deptMapper;
    @Override
    public void add(EmployeeBean em) {
        emMapper.insert(em);
    }

    @Override
    public List<EmployeeBean> findAll() {
        return emMapper.findAll();
    }

    @Override
    public IPage<EmployeeBean> findByItem(Integer pagNO, String name, LocalDate startDate, LocalDate endDate) {
        return emMapper.findByItem(new Page(pagNO,3),name,startDate,endDate);
    }

    @Override
    public EmployeeBean findById(Integer emId) {
        EmployeeBean emBean = emMapper.selectById(emId);
        emBean.setDept(deptMapper.selectById(emBean.getDeptId()));

        return emBean;
    }
}
